package a.面试;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

public class 电话号码_1012 {

    List<String> res = new ArrayList<>();
    StringBuilder tmp = new StringBuilder();
    String s;


    public List<String> letterCombinations(String digits) {
        if(digits=="" || digits.length()==0)return res;//空
        s = digits;
        每组选一个(0);
        return res;
    }

    char[][] c = {
        {},
        {'a','b','c'},
        {'d','e','f'},
        {'g','h','i'},
        {'j','k','l'},
        {'m','n','o'},
        {'p','q','r','s'},
        {'t','u','v'},
        {'w','x','y','z'}
    };
    private void 每组选一个(int step) {
        if(tmp.length() == s.length()) {
            res.add(new String(tmp.toString()));
            return;
        }
        //
        int row = Integer.parseInt(s.charAt(step)+"")-1;//map中取出这层对应的行号
        //
        for (int i = 0; i < c[row].length; i++) {
            tmp.append(c[row][i]);
            每组选一个(step+1);//每次必跳过一个
            tmp.deleteCharAt(tmp.length()-1);
        }
    }
    
    @Test
    public void test() {
        System.out.println(letterCombinations("23"));
    }
}
